package one.stand.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import one.stand.mapper.CompanyCategoryModelMapper;
import one.stand.model.CompanyCategoryModel;
import one.stand.model.ResultModel;
import one.stand.request.CompanyCategoryModelRequest;
import one.stand.service.CompanyCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yandou on 2019/6/13.
 */
@Service
public class CompanyCategoryServiceImpl implements CompanyCategoryService {
    @Autowired
    private CompanyCategoryModelMapper categoryModelMapper;

    @Override
    public ResultModel list(CompanyCategoryModelRequest request) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<CompanyCategoryModel> categoryModelList = categoryModelMapper.selectAll(request.getCompanyCategoryName());
        return ResultModel.success(new PageInfo(categoryModelList));
    }

    @Override
    public ResultModel add(CompanyCategoryModel model) {
        categoryModelMapper.insert(model);
        return ResultModel.success();
    }

    @Override
    public ResultModel delete(CompanyCategoryModel model) {
        categoryModelMapper.deleteByPrimaryKey(model.getCompanyCategoryId());
        return ResultModel.success();
    }
}
